package mww.servlet.student;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import mww.common.DaoException;
import mww.common.Page;
import mww.common.ServiceException;
import mww.javabean.entity.Student;
import mww.javabean.service.StudentService;
import mww.javabean.service.StudentServiceImpl;
public class CheckStudentServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		StudentService service = new StudentServiceImpl();
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String studentNo=request.getParameter("studentNo");
		String studentName=request.getParameter("studentName");
		String studentClass=request.getParameter("studentClass");
		String studentMajor=request.getParameter("studentMajor");
		request.setAttribute("studentNo", studentNo);
		request.setAttribute("studentName", studentName);
		request.setAttribute("studentClass", studentClass);
		request.setAttribute("studentMajor", studentMajor);
		int curPage=1;
		String temp=request.getParameter("curPage");
		if(temp!=null){
			curPage=Integer.parseInt(request.getParameter("curPage"));
		}
  		try{
  			Student st = new Student();
  			st.setStudentNo(studentNo);
  			st.setStudentName(studentName);
  			st.setStudentClass(studentClass);
  			st.setStudentMajor(studentMajor);
	  		Map map = service.findAllStudentByMostCon(st, curPage);
	  		ArrayList list=(ArrayList) map.get("list");
			Page pa=(Page) map.get("pa");
	  		request.setAttribute("curPage", pa.getCurPage());//向显示页传递当前页页码
	  		request.setAttribute("pageCount",pa.getPageCount());//向显示页传递总页数
	  		request.setAttribute("list", list);//向显示页传递结果集
	  		request.getRequestDispatcher("/admin/studentList.jsp").forward(request, response);
  		}catch (ServiceException e) {
			e.printStackTrace();
			request.setAttribute("se", e);
			request.getRequestDispatcher("/serviceException.jsp").forward(request, response);
		} catch (DaoException e) {
			e.printStackTrace();
			request.setAttribute("de", e);
			request.getRequestDispatcher("/daoException.jsp").forward(request, response);
		}
	}
}
